package com.deep.deepenterpise.common.util;

import com.deep.deepenterpise.common.DrUrlConstant;
import com.deep.deepenterpise.common.gas.DrGovernmentApiUrl;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * @author xyz
 * @version 1.0
 * @title DrAuthUtil
 * @description TODO 认证工具类
 * @create 2024/4/16 11:55
 */
@Slf4j
public class DrAuthUtil {

    private DrAuthUtil() {
    }

    /**
     * @return boolean
     * @Auth xyz
     * @Desc //TODO 认证token是否有效
     * @Time 08:56 2024/4/18
     * @Param [drToken]
     */
    public static boolean checkAuth(String drToken) {
        // TODO: check the token and return true or false
        final Map<String, String> params = new HashMap<>();
        params.put("drToken", drToken);

        String result;
        final String url = DrUrlConstant.BASE_URL + DrUrlConstant.POST_AUTH_URL;
        try {
            result = DrOkHttpUtil.httpPost(url, null, params);
            if (StringUtils.isEmpty(result)) {
                return false;
            }
            return DrRequestUtil.isSuccess(result);
        } catch (Exception e) {
            log.error("[doAuth调用失败]-------" + DrCommonUtil.drGetStackTraceInfo(e));
            return false;
        }
    }
}
